core.resize = {};
core.resize.enableResize = function(){
    
};

//#ifdef DESKTOP

core.resize.enableResize = function(config){
    var left = config.left || false;
    var right = config.right || false;
    var top = config.top || false;
    var bottom = config.bottom || false;
    var _class = null;
    var border = config.border || 4;
    var side = -1;
    var area = config.area || core.desktop.items[0].div;
    var backDiv = null;
    var mainDiv = null;
    var innDiv = null;
    $(config.div).mouseover(function(e){
    }).mousemove(function(e){
        if(_class)
            $(config.div).removeClass(_class);
        _class = null;
        var divPos = $(config.div).position();
        var x = e.clientX-divPos.left;
        var y = e.clientY-divPos.top;
        var width = $(config.div).width();
        var height = $(config.div).height();
        side = -1;
        if(left && x<border){
            _class = 'left-resize';
            side = 0;
        }
        if(top && y<border){
            _class = 'top-resize';
            side = 3;
        }
        if(right && width-x-1<border){
            _class = 'right-resize';
            side = 2;
        }
        if(bottom && height-y-1<border){
            _class = 'bottom-resize';
            side = 1;
        }
        if(_class)
            $(config.div).addClass(_class);
        return true;
    }).mouseout(function(){
        if(_class)
            $(config.div).removeClass(_class);
        return true;
    }).mousedown(function(e){
        if(side!=-1){
            //Create layers
            var areaPos = $(area).position();
            backDiv = core.newDiv(core.desktop.div, 'resize-background '+_class);
            mainDiv = core.newDiv(core.desktop.div, 'resize-main');
            innDiv = core.newDiv(mainDiv, 'resize-inner');
            $(innDiv).html('');
            $(backDiv).css('left', areaPos.left).
                css('top', areaPos.top).
                width($(area).width()).height($(area).height()).
            mousemove(function(e){
                resizeBorder(e.clientX, e.clientY);
                return false;
            }).mouseup(function(e){
                cancelBorder(e);
                return false;
            }).mouseout(function(){
                cancelBorder();
                return false;
            });
            resizeBorder(e.clientX, e.clientY);
            core.clearSelection();
            return false;
        }
        return true;
    });

    var cancelBorder = function(e){
        if(e){
            var size = resizeBorder(e.clientX, e.clientY);
            if(config.handler)
                config.handler(size);
        }
        $(innDiv).remove();
        $(mainDiv).remove();
        $(backDiv).remove();
    };
    var resizeBorder = function(x, y){
        var areaPos = $(area).position();
        var divPos = $(config.div).position();
        var divWidth = $(config.div).width();
        var divHeight = $(config.div).height();
        if(side==0){//Left
            divWidth += (divPos.left-x);
            divPos.left = x;
        }
        if(side==3){//Top
            divHeight += (divPos.top-y);
            divPos.top = y;
        }
        if(side==2){//Right
            divWidth = (x-divPos.left);
        }
        if(side==1){//Bottom
            divHeight = (y-divPos.top);
        }
        $(mainDiv).css('left', divPos.left)
            .css('top', divPos.top).
                width(divWidth).height(divHeight);
        var sizeDec = $.browser.msie?0:4;
        $(innDiv).width(divWidth-sizeDec).height(divHeight-sizeDec);
        return {
            width: divWidth,
            height: divHeight
        };
    };
};

//#endif
